<?php

/**
 * Description of Log
 *
 * 
 * @author		Marat Mitypov
 * @link		http://www.mitypov.ru
 * @copyright		2011 Marat Mitypov (marat@mitypov.ru)
 * @license		GNU General Public License 3 (http://www.gnu.org/licenses/)
 * @version             $Id: Log.class.php 3 2011-11-30 12:00:32Z marat@mitypov.ru $
 */
class Log {

    private $FileName;
    private $DateTime;
    
    /**
     *
     * @param type $iFileName 
     */
    public function __construct($iFileName='log_file.log') {
        $this->FileName = $iFileName;
        $handle =  fopen($this->FileName, 'a+');
        fclose($handle);
        $this->SetDateTimeFormat();
    }
    
    /**
     *
     * @param type $iText 
     */
    public function Write($iText) {
        if (!is_writable($this->FileName))
            die ("Change your CHMOD permissions for $this->FileName");
        
            $handle =  fopen($this->FileName, 'a+');
            fwrite($handle, $this->GetDateTime() . $iText . "\r");
            fclose($handle);
        
    }
    
    public function Log($iText){
        $this->Write($iText);
    }
    
    public function Show() {
        $handle = fopen($this->FileName, 'r');
        return file_get_contents($this->FileName);
    }
    
    /**
     *
     * @return type 
     */
    public function GetDateTime() {
        return $this->DateTime;
    }
    
    public function SetDateTimeFormat($DateTimeFormat='d.m.Y H:i:s') {
        $this->DateTime = date($DateTimeFormat).' ';
    }
}

?>
